package cn.zn.verify.strategy.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.zn.base.bean.vo.BaseApiVo;
import cn.zn.base.common.utils.SpringContextUtil;
import cn.zn.verify.annotation.Custom;
import cn.zn.verify.component.CustomVerifyComponent;
import cn.zn.verify.strategy.VerifyStrategy;

import java.lang.annotation.Annotation;

/**
 * 必填项校验策略
 */
public class CustomVerifyStrategy<V extends BaseApiVo> implements VerifyStrategy<V> {

    @Override
    public <T extends Annotation> String verify(Object value, V vo, T annotation) {
        if (ObjectUtil.isEmpty(value)) {
            return null;
        }

        String verifyBean = ((Custom) annotation).verifyBean();
        CustomVerifyComponent<V> customVerifyComponent = SpringContextUtil.getBean(verifyBean);
        return customVerifyComponent.verify(vo);
    }
}
